package zzcltw.com.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import zzcltw.com.mapper.SystemMapper;
import zzcltw.com.object.SysMenu;
import zzcltw.com.service.ISystemService;
import zzcltw.com.service.common.impl.BaseServiceImpl;

@Service("systemService")
public class SystemServiceImpl extends BaseServiceImpl implements ISystemService{
	@Autowired
	private SystemMapper systemMapper;
	/**
	 * 
	 * @Title  菜单列表查询
	 * @Description:  
	 * @param: @param 
	 * @param: @return
	 * @return 
	 * @throws
	 * @author zzx
	 * @Date 2018年9月15日
	 */
	public Map<String,Object> queryMenuList(Map<String,String> map){
		List<Map<String,String>> list = systemMapper.queryMenuList(map);
		int count = systemMapper.queryMenuListCount(map);
		Map<String,Object> bean = new HashMap<>();
		bean.put("total", Integer.toString(count));
		Map<String,Object> map1 = new HashMap<>();
		map1.put("beans", list);
		map1.put("bean", bean);
		map1.put("busiCode", "");
    	map1.put("returnCode", "0");
    	map1.put("returnMessage", "");
    	map1.put("object", list);
    	map1.put("busiCode", ""); 
		return map1;
	}
	/**
	 * 
	 * @Title  首页菜单列表
	 * @Description:  
	 * @param: @param 
	 * @param: @return
	 * @return 
	 * @throws
	 * @author zzx
	 * @Date 2018年9月15日
	 */
	public Map<String,Object> queryMenuLeftTop(Map<String,String> map){
		map.put("superMenuId", "0");
		List<Map<String,String>> list = systemMapper.queryMenuLeftTop(map);
		List<Map<String,Object>> object = new ArrayList<>();
		for(Map<String,String> m : list){
			Map<String,Object> oM = new HashMap<>();
			Map<String,String> params = new HashMap<>();
			params.put("superMenuId",m.get("menuId"));
			List<Map<String,String>> subList = systemMapper.queryMenuLeftTop(params);
			oM.putAll(m);
			oM.put("tMenu", subList);
			object.add(oM);
		}
		Map<String,Object> map1 = new HashMap<>();
		map1.put("beans", null);
		map1.put("bean", null);
		map1.put("busiCode", "");
    	map1.put("returnCode", "0");
    	map1.put("returnMessage", "");
    	map1.put("object", object);
    	map1.put("busiCode", ""); 
		return map1;
	}
	/**
	 * 
	 * @Title  菜单详情
	 * @Description:  queryMenuDtlById
	 * @param: @param 
	 * @param: @return
	 * @return 
	 * @throws
	 * @author zzx
	 * @Date 2018年9月15日
	 */
	public Map<String,Object> queryMenuDtlById(Map<String,String> map){
		Map<String,String> bean = systemMapper.queryMenuDtlById(map);
		Map<String,Object> map1 = new HashMap<>();
		map1.put("beans", null);
		map1.put("bean", bean);
		map1.put("busiCode", "");
    	map1.put("returnCode", "0");
    	map1.put("returnMessage", "");
    	map1.put("object", "");
    	map1.put("busiCode", ""); 
		return map1;
	}
	/**
	 * 
	 * @Title  菜单新增
	 * @Description:  saveMenuInfo
	 * @param: @param 
	 * @param: @return
	 * @return 
	 * @throws Exception 
	 * @throws
	 * @author zzx
	 * @Date 2018年9月15日
	 */
	public Map<String,Object> saveMenuInfo(SysMenu sysMenu) throws Exception{
		String uiId = getSequence("t_pi_ui");		
		sysMenu.setUiId(uiId);
		int flag = systemMapper.saveMenuInfo(sysMenu);
		Map<String,Object> bean = new HashMap<>();
    	if(flag != 1){
    		bean.put("rtnCd", "9999");
    	}else {
    		bean.put("rtnCd", "00");
    	}
    	Map<String,Object> map1 = new HashMap<>();
		map1.put("bean", bean);
		map1.put("busiCode", "");
    	map1.put("returnCode", "0");
    	map1.put("returnMessage", "");
    	map1.put("object", "");
    	map1.put("busiCode", "");		
    	return map1;
	}
	/**
	 * 
	 * @Title  菜单编辑
	 * @Description:  updateMenuInfo
	 * @param: @param 
	 * @param: @return
	 * @return 
	 * @throws
	 * @author zzx
	 * @Date 2018年9月15日
	 */
	public Map<String,Object> updateMenuInfo(SysMenu sysMenu)throws Exception{
		int flag = systemMapper.updateMenuInfo(sysMenu);
		Map<String,Object> bean = new HashMap<>();
    	if(flag != 1){
    		bean.put("rtnCd", "9999");
    	}else {
    		bean.put("rtnCd", "00");
    	}
    	Map<String,Object> map1 = new HashMap<>();
		map1.put("bean", bean);
		map1.put("busiCode", "");
    	map1.put("returnCode", "0");
    	map1.put("returnMessage", "");
    	map1.put("object", "");
    	map1.put("busiCode", "");		
    	return map1;
	}
	/**
	 * 
	 * @Title  菜单删除
	 * @Description:  delMenuInfo
	 * @param: @param 
	 * @param: @return
	 * @return 
	 * @throws
	 * @author zzx
	 * @Date 2018年9月15日
	 */
	public Map<String,Object> delMenuInfo(SysMenu sysMenu){
		int count = systemMapper.delMenuInfo(sysMenu);
		Map<String,Object> map1 = new HashMap<>();
		map1.put("beans", "");
		map1.put("bean", "");
		map1.put("busiCode", "");
    	map1.put("returnCode", "0");
    	map1.put("returnMessage", "");
    	map1.put("object", "");
    	map1.put("busiCode", ""); 
		return map1;
	}
}
